package org.aplombh.java.utils.multiThread.create;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.util.stream.IntStream;

import static org.aplombh.java.utils.WebDownloader.downloader;

/**
 * 继承Thread类
 * <p>
 * 子类继承Thread类具备多线程能力
 * 启动线程:子类对象. start()
 * 不建议使用: 避免OOP单继承局限性
 */
@AllArgsConstructor
@NoArgsConstructor
public class TestThread extends Thread {
    private String url;
    private String name;

    @Override
    public void run() {
        downloader(url, name);
        System.out.println("download:" + name);
    }

    public static void main(String[] args) {
        Thread thread1 = new TestThread("https://www.baidu.com/img/flexible/logo/pc/result.png", "1.jpg");
        Thread thread2 = new TestThread("https://www.baidu.com/img/flexible/logo/pc/result.png", "2.jpg");
        Thread thread3 = new TestThread("https://www.baidu.com/img/flexible/logo/pc/result.png", "3.jpg");

        thread1.start();
        thread2.start();
        thread3.start();

        IntStream.range(0, 10).forEach(i -> System.out.println("-_-_-_-_-_-_-_-_- " + i));
    }
}
